package sz.szsmk.citizencard.ui.newversion.activity.adapter

import android.widget.CheckBox
import android.widget.ImageView
import android.widget.RadioButton
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.drawable.GlideDrawable
import com.bumptech.glide.request.target.Target
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import sz.szsmk.citizencard.R
import sz.szsmk.citizencard.model.network.dzbean.res.SupportBankResponse

/**
 *  author : hyt
 *  date : 2020/10/19
 *  description :
 */
class BindBankCardAdapter :BaseQuickAdapter<SupportBankResponse.DataBean, BaseViewHolder>(R.layout.layout_bindbankcard) {


    override fun convert(helper: BaseViewHolder?, item: SupportBankResponse.DataBean?) {
        helper?.setText(R.id.tv_bankName, item?.bankName)
        Glide.with(mContext).load(item?.bankIconUrl).into(helper?.getView(R.id.iv_bankimg))

        if(item?.isCheck!!){
            helper?.getView<ImageView>(R.id.iv_bank)?.setImageResource(R.mipmap.ic_bindbank_check)
        }else{
            helper?.getView<ImageView>(R.id.iv_bank)?.setImageResource(R.mipmap.ic_bindbank_check_normal)
        }

        helper?.getView<ImageView>(R.id.iv_bank)?.setOnClickListener {v ->
            for( temp in this.data){
                temp.isCheck = false
            }
            item.isCheck = !item.isCheck
            notifyDataSetChanged()
        }
    }

    fun getCheckItem(): SupportBankResponse.DataBean? {
        var result:SupportBankResponse.DataBean?=null
        for( temp in this.data){
            if(temp.isCheck){
                result = temp
                break
            }
        }
        return result
    }
    fun getBankCode(): String? {
        for( temp in this.data){
            if(temp.isCheck){
                return temp.bankCode
                break
            }
        }
        return ""
    }



}